home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6827 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: gate.itron.com!usenet
  2. From: ronald.ten-hove@itron.com (Ron Ten-Hove)
  3. Newsgroups: comp.lang.c,comp.lang.c++,comp.os.ms-windows.programmer.misc,comp.os.msdos.programmer,comp.programming,comp.windows.ms.programmer
  4. Subject: Re: Date Arithmetic
  5. Date: 20 Feb 1996 00:12:45 GMT
  6. Organization: Itron Inc.
  7. Message-ID: <4gb3lt$7vf@gate.itron.com>
  8. References: <4g19kp$640@tracy.protocom.com>
  9. Reply-To: ronald.ten-hove@itron.com (Ron Ten-Hove)
  10. NNTP-Posting-Host: itron12-23.itron.com
  11. X-Newsreader: IBM NewsReader/2 v1.02
  12.  
  13. In <4g19kp$640@tracy.protocom.com>, "Michael J. Karas" <mkaras@pclink.com> writes:
  14. >I am working on an algorithm for a laser marking machine that writes
  15. >expiration delays on to food product boxes. The algorithm needs to 
  16. >be able to add NNN days to todays date in the fastest manner possible
  17. >without using any floating point arithmetic. I could use help from anyone
  18. >that has C code for doing this. It would be nice if the solution took the
  19. >leap year problem in to account including the special case of the year 
  20. >2000. Thanks in advance to anyone who could share their knowledge on this 
  21. >subject.
  22.  
  23. What you need is a two-way conversion process:
  24.  
  25.     calendar-date -> Julian-date
  26.     Jullian-date -> calendar-date
  27.  
  28. You can convert the current date to Julian, add NNN days, and convert
  29. back to normal calendar date.
  30.  
  31. Many libraries include Julian date calculations.  If you are
  32. using C++, for example, the Rogue Wave tools.h++ library has an excellent
  33. class named RWDate that will convert between Julian and calendar
  34. dates very easily.
  35.  
  36. There are *many* unix shell scripts that show the basic algorithms
  37. used for such conversions.  I believe the ACM has documented them
  38. in their ``Collected Algorithms'' books.
  39.  
  40. -Ron
  41.  
  42.  
  43.